import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;

import javax.print.DocFlavor.URL;

import com.golden.gamedev.Game;
import com.golden.gamedev.GameLoader;
import com.golden.gamedev.object.Background;
import com.golden.gamedev.object.Sprite;
import com.golden.gamedev.object.Timer;
import com.golden.gamedev.object.background.ColorBackground;
import com.golden.gamedev.object.background.ImageBackground;


public class practiceGame1 extends Game{

	
	Sprite hero;
	Timer fireRate;
	Background cover1;
	Background cover2;
	Sprite villian;
	
	@Override
	public void initResources() {
	    BufferedImage bird    = getImage("Bird.gif");
        BufferedImage[] cat = getImages("Cat.gif", 3, 1);

        setFPS(50);
        java.net.URL url = bsIO.getURL("pond3.jpg");
        
        //different background layers
        cover1 = new ColorBackground(Color.CYAN,200,200);
        cover2 = new ImageBackground(getImage("pond3.jpg"), 150, 100);
        
        
        //animatable character
        hero = new Sprite(bird, 100.0, 100.0);
        hero.setSpeed(.05, .1);
        
        villian = new Sprite(cat[0], 200.0, 200.0);
        villian.setSpeed(-.08, -.04);
        
        hero.setBackground(cover1);
        cover1.setToCenter(hero);
        villian.setBackground(cover2);
	}

	
	
	@Override
	public void render(Graphics2D g) {
		g.setColor(Color.BLUE);
	    g.fillRect(0, 0, getWidth(), getHeight());
	    hero.render(g);
	    cover1.render(g);
	    cover2.render(g);
	    villian.render(g);
	}

	@Override
	public void update(long elapsedTime) {
		hero.update(elapsedTime);
		cover1.update(elapsedTime);
		cover2.update(elapsedTime);
		villian.update(elapsedTime);
		if (keyPressed(KeyEvent.VK_DOWN)) {
			hero.move(0, 0.1*elapsedTime);
			setMaskColor(Color.GREEN);
			}
		// if (fireRate.action(elapsedTime)) {
	           // fire!!
	         //  playSound("fire.wav");
	     //   }


	}

	public static void main(String[] args){
		practiceGame1 practice = new practiceGame1();
		GameLoader game = new GameLoader();
		game.setup(practice, new Dimension(640,480), true);
		game.start();
	}
}
